extends Area2D

@export var horizontal_speed = -10 # 垂直移动速度
@export var vertical_speed = -10 #水平移动速度
@export var max_height = 200 # 水平高度
var direction:Vector2 = Vector2(1,1)
var player

func _ready():
	player = get_tree().get_first_node_in_group("player")
	if player.animated_sprite_2d.flip_h:
		direction.x = -1

func _process(delta):
	position.y += horizontal_speed * direction.y * delta
	position.x += vertical_speed * direction.x * delta
	if position.y <= max_height:
		direction.y = -1


func _on_body_entered(body):
	if body.is_in_group("ground"):
		direction.y = 1
	elif body.is_in_group("enemy"):
		body.hurt()
	pass # Replace with function body.
